﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using C_sports_meet.ServiceReference3;
using System.ServiceModel;


namespace C_sports_meet.Athlete
{
    /// <summary>
    /// AExitRace.xaml 的交互逻辑
    /// </summary>
    public partial class AExitRace : Page, IService1Callback
    {
        public string UserName { get; set; }
        private Service1Client client; // 客户端代理类，用于客户端调用服务端方法
        private InstanceContext context; // 让服务端通过InstanceContext知道通信的是哪个客户端对象
        public AExitRace()
        {
            InitializeComponent();
            context = new InstanceContext(this); // 获取当前InstanceContext
            client = new Service1Client(context); // 根据InstanceContext创建客户端代理类
            Text1.Text = Login.LoggedOutUser;
            UserName = Text1.Text;
        }
        private void Window_Loaded_1(object sender, RoutedEventArgs e)
        {
            Text1.Text = Login.LoggedOutUser;
        }
        private void BtnInto_Click(object sender, RoutedEventArgs e)
        {
            DataRowView mySelectedElement = (DataRowView)DataGrid1.SelectedItem;
            string result = mySelectedElement.Row[0].ToString();
            bool index = client.Delete(result, UserName);
            if (index)
            {
                MessageBox.Show("退选成功");
            }
            else
            {
                MessageBox.Show("退选失败，请重试");
            }
        }
        private void BtnSelect1_Click(object sender, RoutedEventArgs e)
        {
            string strCon = "server=.;database=sportmeet;user=sa;pwd=Lss200217";
            SqlConnection con = new SqlConnection(strCon);
            string strSql = "select eevent.eno 项目编号,eevent.ename 项目名称,etime 比赛时间,fname 项目类别,jname 裁判姓名,sname 场地名称 from eevent,form,site,judge,signup where eevent.fno='202207001'and ano='" + Text1.Text + "' and eevent.fno=form.fno and eevent.sno=site.sno and eevent.jno=judge.jno and signup.eno=eevent.eno";
            SqlCommand cmd = new SqlCommand(strSql, con);
            con.Open();
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable dataTable = new DataTable();
            adapter.Fill(dataTable);
            DataGrid1.ItemsSource = dataTable.DefaultView;
            con.Close();
        }

        private void BtnSelect2_Click(object sender, RoutedEventArgs e)
        {
            string strCon = "server=.;database=sportmeet;user=sa;pwd=Lss200217";
            SqlConnection con = new SqlConnection(strCon);
            string strSql = "select eevent.eno 项目编号,eevent.ename 项目名称,etime 比赛时间,fname 项目类别,jname 裁判姓名,sname 场地名称 from eevent,form,site,judge,signup where eevent.fno='202207002'and ano='" + Text1.Text + "' and eevent.fno=form.fno and eevent.sno=site.sno and eevent.jno=judge.jno and signup.eno=eevent.eno";
            SqlCommand cmd = new SqlCommand(strSql, con);
            con.Open();
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable dataTable = new DataTable();
            adapter.Fill(dataTable);
            DataGrid1.ItemsSource = dataTable.DefaultView;
            con.Close();

        }

        private void BtnSelect3_Click(object sender, RoutedEventArgs e)
        {
            string strCon = "server=.;database=sportmeet;user=sa;pwd=Lss200217";
            SqlConnection con = new SqlConnection(strCon);
            string strSql = "select eevent.eno 项目编号,eevent.ename 项目名称,etime 比赛时间,fname 项目类别,jname 裁判姓名,sname 场地名称 from eevent,form,site,judge,signup where eevent.fno='202207003'and ano='" + Text1.Text + "' and eevent.fno=form.fno and eevent.sno=site.sno and eevent.jno=judge.jno and signup.eno=eevent.eno";
            SqlCommand cmd = new SqlCommand(strSql, con);
            con.Open();
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable dataTable = new DataTable();
            adapter.Fill(dataTable);
            DataGrid1.ItemsSource = dataTable.DefaultView;
            con.Close();

        }

        private void BtnSelect4_Click(object sender, RoutedEventArgs e)
        {
            string strCon = "server=.;database=sportmeet;user=sa;pwd=Lss200217";
            SqlConnection con = new SqlConnection(strCon);
            string strSql = "select eevent.eno 项目编号,eevent.ename 项目名称,etime 比赛时间,fname 项目类别,jname 裁判姓名,sname 场地名称 from eevent,form,site,judge,signup where eevent.fno='202207004'and ano='" + Text1.Text + "' and eevent.fno=form.fno and eevent.sno=site.sno and eevent.jno=judge.jno and signup.eno=eevent.eno";
            SqlCommand cmd = new SqlCommand(strSql, con);
            con.Open();
            SqlDataAdapter adapter = new SqlDataAdapter(cmd);
            DataTable dataTable = new DataTable();
            adapter.Fill(dataTable);
            DataGrid1.ItemsSource = dataTable.DefaultView;
            con.Close();
        }

        public void ShowResults(DataTable dt, int res)
        {
            throw new NotImplementedException();
        }
    }
}
